
const path = require('path')
/*
babel缓存 cacheDirectory:true 让第二次打包更快
*/
// 复用loader
const commonCssLoader = [
    'style-loader',
    'css-loader',
];
module.exports = {
    entry: './index.js',
    output: {
        filename: 'js/index.js',
        path: path.resolve(__dirname, 'dist')
    },
    module: {
        rules: [
            // {
            //     //语法检测
            //     test: /\.js$/i,
            //     loader: 'eslint-loader',
            //     exclude: /node_modules/,
            //     enforce: 'pre',//优先执行
            //     options: {
            //         fix: true//自动修改eslint错误
            //     }
            // },
            {
                oneOf: [//每个loader只会匹配一个
                    {
                        test: /\.less$/,
                        use: [...commonCssLoader]
                    },
                    {
                        test: /\.scss$/,
                        use: [...commonCssLoader]
                      },
                    {
                        //处理js版本转义
                        test: /\.js$/i,
                        loader: 'babel-loader',
                        exclude: /node_modules/,
                        options: {
                            cacheDirectory: true,//开启babel缓存，第二次建构时，会读取之前的缓存,解决修改后全部重新编译
                        }
                    },
                ]
            }
        ]
    },
    plugins: [
    ],
    mode: 'production'
}